﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using XiaoGang.Soft.XGWMS.COM;
using System.IO;
using System.Reflection;

namespace XiaoGang.Soft.XGWMS.UI
{
    public partial class M012_STORAGESCAN : FormBase
    {
        #region 变量定义

        bool blFormLoad = false;
        XGWMS.BLL.BLL_M012_STORAGESCAN bll_M012_STORAGESCAN = new XiaoGang.Soft.XGWMS.BLL.BLL_M012_STORAGESCAN();
        //string strGroupTitle = "检索结果@@@   提示：双击各商品可查看该商品的进/出库流水信息";
        string strGroupTitle = "检索结果@@@";
        BLL.BLL_M014BILLSCAN bll_M014BILLSCAN = new XiaoGang.Soft.XGWMS.BLL.BLL_M014BILLSCAN();
        BLL.BLL_M007_GOODS bll_M007 = new XiaoGang.Soft.XGWMS.BLL.BLL_M007_GOODS();
        private const string dataName = "库存";
        private bool IsInitiral = true;
        //string strGoodID = "";
        private readonly MODEL.MOD_M012_STORAGESCAN entitySearch;
        #endregion

        #region 方法

        public M012_STORAGESCAN()
        {
            InitializeComponent();
            entitySearch = new XiaoGang.Soft.XGWMS.MODEL.MOD_M012_STORAGESCAN();
        }

        /// <summary>	
        /// <p><b>方法名称</b>SetTabIndex</p>	
        /// <p><b>概要説明	:</b>画面フォーカスの遷移順の設定</p>	
        /// <p><b>作成者	:</b>万岗</p>	
        /// <p><b>作成日	:</b>2008/09/08</p>	
        /// </summary>
        private void SetTabIndex()
        {
            int intIndex = 0;            
            txtGOODS_ID.TabIndex = intIndex; intIndex++;
            //btnGoodsIDSearch.TabIndex = intIndex; intIndex++;
            cmbGOODS_GROUP_ID.TabIndex = intIndex; intIndex++;
        }

        /// <summary>	
        /// <p><b>方法名称</b>ClearControl</p>	
        /// <p><b>概要説明	:</b>画面上の全項目をオールクリアする</p>	
        /// <p><b>作成者	:</b>万岗</p>	
        /// <p><b>作成日	:</b>2008/09/08</p>	
        /// </summary>
        private void ClearControl()
        {            
            txtGOODS_ID.Text = "";
            cmbGOODS_GROUP_ID.SelectedIndex = 0;
            grpSearchResult.Text = strGroupTitle.Replace("@@@","");

            lbGOODS_ID.Text = "";
            lbGOODS_NM1.Text = "";
            lbAllUnits.Text = "";
            lbGOODS_GROUP.Text = "";
            lbPROVIDER.Text = "";
            lbMEMO.Text = "";
        }

        /// <summary>	
        /// <p><b>方法名称</b>SetEnable</p>	
        /// <p><b>概要説明  :</b>画面モードのセト</p>
        /// <p><b>作成者	:</b>万岗</p>	
        /// <p><b>作成日	:</b>2008/09/08</p>	
        /// <p><b>修改历史  :</b></p>	
        /// </summary>	
        private void SetEnable()
        {
            grpSearch.Enabled = true;
            txtGOODS_ID.Enabled = true;
            //btnGoodsIDSearch.Enabled = true;
            cmbGOODS_GROUP_ID.Enabled = true;

            grpSearchResult.Enabled = true;
            grdmentStorageInfo.Enabled = true;
        }

        /// <summary>	
        /// <p><b>方法名称</b>InitialGridView</p>	
        /// <p><b>概要説明	:</b>窗口初始化</p>	
        /// <p><b>作成者	:</b>万岗</p>	
        /// <p><b>作成日	:</b>2008/09/08</p>	
        /// </summary>
        private void InitialGridView()
        {
            grdmentStorageInfo.ReadOnly = true;
            grdmentStorageInfo.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
            grdmentStorageInfo.ColumnHeadersBorderStyle = DataGridViewHeaderBorderStyle.Raised;
            grdmentStorageInfo.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.DisableResizing;
            grdmentStorageInfo.ColumnHeadersHeight = 30;
            grdmentStorageInfo.ColumnHeadersVisible = true;
            grdmentStorageInfo.AllowUserToResizeColumns = true;
            grdmentStorageInfo.ColumnHeadersDefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;

            grdmentStorageInfo.Columns.Add("NO.", "NO.");
            grdmentStorageInfo.Columns.Add("GOODS_ID", "商品编号");
            grdmentStorageInfo.Columns.Add("GOODS_NO", "商品条码");
            grdmentStorageInfo.Columns.Add("GOODS_NM", "商品名称");
            grdmentStorageInfo.Columns.Add("GOODS_GROUP_ID", "商品分类编号");
            grdmentStorageInfo.Columns.Add("GOODS_GROUP_NM", "商品分类");
            grdmentStorageInfo.Columns.Add("UNITS", "数量");
            grdmentStorageInfo.Columns.Add("STOREROOM_NM", "仓库");
            grdmentStorageInfo.Columns.Add("PROVIDER", "供应商");
            grdmentStorageInfo.Columns.Add("MAX_WARN", "最大库存警戒");
            grdmentStorageInfo.Columns.Add("MIN_WARN", "最小库存警戒");
            grdmentStorageInfo.Columns.Add("STOREROOM_ID", "仓库编号");
            grdmentStorageInfo.Columns["NO."].Width = 50;
            grdmentStorageInfo.Columns["NO."].Frozen = true;
            grdmentStorageInfo.Columns["NO."].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
            grdmentStorageInfo.Columns["NO."].SortMode = DataGridViewColumnSortMode.NotSortable;
            grdmentStorageInfo.Columns["NO."].Resizable = DataGridViewTriState.False;
            grdmentStorageInfo.Columns["GOODS_ID"].Width = 150;
            grdmentStorageInfo.Columns["GOODS_ID"].Frozen = true;
            grdmentStorageInfo.Columns["GOODS_ID"].Resizable = DataGridViewTriState.False;
            grdmentStorageInfo.Columns["GOODS_ID"].SortMode = DataGridViewColumnSortMode.NotSortable;

            grdmentStorageInfo.Columns["GOODS_NO"].Width = 150;
            grdmentStorageInfo.Columns["GOODS_NO"].Resizable = DataGridViewTriState.False;
            grdmentStorageInfo.Columns["GOODS_NO"].SortMode = DataGridViewColumnSortMode.NotSortable;

            grdmentStorageInfo.Columns["GOODS_NM"].Width = 200;
            grdmentStorageInfo.Columns["GOODS_NM"].Frozen = true;
            grdmentStorageInfo.Columns["GOODS_NM"].SortMode = DataGridViewColumnSortMode.NotSortable;
            grdmentStorageInfo.Columns["GOODS_GROUP_ID"].Width = 0;
            grdmentStorageInfo.Columns["GOODS_GROUP_ID"].Visible = false;
            grdmentStorageInfo.Columns["GOODS_GROUP_NM"].Width = 150;
            grdmentStorageInfo.Columns["GOODS_GROUP_NM"].SortMode = DataGridViewColumnSortMode.NotSortable;
            grdmentStorageInfo.Columns["GOODS_GROUP_NM"].Resizable = DataGridViewTriState.False;
            grdmentStorageInfo.Columns["UNITS"].Width = 60;
            grdmentStorageInfo.Columns["UNITS"].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight;
            grdmentStorageInfo.Columns["UNITS"].SortMode = DataGridViewColumnSortMode.NotSortable;
            grdmentStorageInfo.Columns["UNITS"].Resizable = DataGridViewTriState.False;
            grdmentStorageInfo.Columns["PROVIDER"].Width = 150;
            grdmentStorageInfo.Columns["PROVIDER"].SortMode = DataGridViewColumnSortMode.NotSortable;
            grdmentStorageInfo.Columns["PROVIDER"].Visible = false;
            grdmentStorageInfo.Columns["MAX_WARN"].Width = 80;
            grdmentStorageInfo.Columns["MAX_WARN"].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight;
            grdmentStorageInfo.Columns["MAX_WARN"].SortMode = DataGridViewColumnSortMode.NotSortable;
            grdmentStorageInfo.Columns["MAX_WARN"].Visible = false;
            grdmentStorageInfo.Columns["MIN_WARN"].Width = 80;
            grdmentStorageInfo.Columns["MIN_WARN"].DefaultCellStyle.Alignment =  DataGridViewContentAlignment.MiddleRight;
            grdmentStorageInfo.Columns["MIN_WARN"].SortMode = DataGridViewColumnSortMode.NotSortable;
            grdmentStorageInfo.Columns["MIN_WARN"].Visible = false;
            grdmentStorageInfo.Columns["STOREROOM_ID"].Width = 0;
            grdmentStorageInfo.Columns["STOREROOM_ID"].Visible = false;
            grdmentStorageInfo.Columns["STOREROOM_ID"].SortMode = DataGridViewColumnSortMode.NotSortable;
            grdmentStorageInfo.Columns["STOREROOM_NM"].Width = 200;
            grdmentStorageInfo.Columns["STOREROOM_NM"].SortMode = DataGridViewColumnSortMode.NotSortable;

            grdmentStorageInfo.AllowUserToAddRows = false;
            grdmentStorageInfo.AllowUserToDeleteRows = false;
            grdmentStorageInfo.AllowUserToResizeRows = false;
            grdmentStorageInfo.RowHeadersVisible = false;
            grdmentStorageInfo.RowTemplate.Height = 20;
            grdmentStorageInfo.RowTemplate.ReadOnly = true;
            grdmentStorageInfo.RowTemplate.Resizable = DataGridViewTriState.False;
        }

        protected void InitialGridViewDetail()
        {
            grdmentBillDetailInfo.ColumnHeadersBorderStyle = DataGridViewHeaderBorderStyle.Raised;
            grdmentBillDetailInfo.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
            grdmentBillDetailInfo.ReadOnly = true;
            grdmentBillDetailInfo.ColumnHeadersHeight = 30;
            grdmentBillDetailInfo.ColumnHeadersVisible = true;
            grdmentBillDetailInfo.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing;

            grdmentBillDetailInfo.Columns.Add("NO.", "NO.");
            grdmentBillDetailInfo.Columns.Add("BUSINESS_TIME", "时间");
            grdmentBillDetailInfo.Columns.Add("IN_OUT_Name", "业务");
            grdmentBillDetailInfo.Columns.Add("UNITS", "数量");
            grdmentBillDetailInfo.Columns.Add("PRICE", "价格");
            grdmentBillDetailInfo.Columns.Add("MEMO", "备注");

            grdmentBillDetailInfo.Columns["NO."].Width = 50;
            grdmentBillDetailInfo.Columns["NO."].Frozen = true;
            grdmentBillDetailInfo.Columns["NO."].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
            grdmentBillDetailInfo.Columns["NO."].SortMode = DataGridViewColumnSortMode.NotSortable;
            grdmentBillDetailInfo.Columns["NO."].Resizable = DataGridViewTriState.False;
            grdmentBillDetailInfo.Columns["BUSINESS_TIME"].Width = 100;
            grdmentBillDetailInfo.Columns["BUSINESS_TIME"].CellTemplate.Style.Alignment = DataGridViewContentAlignment.MiddleCenter;
            grdmentBillDetailInfo.Columns["BUSINESS_TIME"].HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter;
            grdmentBillDetailInfo.Columns["BUSINESS_TIME"].SortMode = DataGridViewColumnSortMode.NotSortable;
            grdmentBillDetailInfo.Columns["BUSINESS_TIME"].Resizable = DataGridViewTriState.False;
            grdmentBillDetailInfo.Columns["IN_OUT_Name"].Width = 60;
            grdmentBillDetailInfo.Columns["IN_OUT_Name"].Frozen = true;
            grdmentBillDetailInfo.Columns["IN_OUT_Name"].Resizable = DataGridViewTriState.False;
            grdmentBillDetailInfo.Columns["IN_OUT_Name"].CellTemplate.Style.Alignment = DataGridViewContentAlignment.MiddleCenter;
            grdmentBillDetailInfo.Columns["IN_OUT_Name"].HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter;
            grdmentBillDetailInfo.Columns["IN_OUT_Name"].SortMode = DataGridViewColumnSortMode.NotSortable;
            grdmentBillDetailInfo.Columns["UNITS"].Width = 60;
            grdmentBillDetailInfo.Columns["UNITS"].HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter;
            grdmentBillDetailInfo.Columns["UNITS"].CellTemplate.Style.Alignment = DataGridViewContentAlignment.MiddleRight;
            grdmentBillDetailInfo.Columns["UNITS"].SortMode = DataGridViewColumnSortMode.NotSortable;
            grdmentBillDetailInfo.Columns["UNITS"].Resizable = DataGridViewTriState.False;
            grdmentBillDetailInfo.Columns["PRICE"].Width = 80;
            grdmentBillDetailInfo.Columns["PRICE"].Visible = false;
            grdmentBillDetailInfo.Columns["PRICE"].HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleRight;
            grdmentBillDetailInfo.Columns["PRICE"].CellTemplate.Style.Alignment = DataGridViewContentAlignment.MiddleRight;
            grdmentBillDetailInfo.Columns["MEMO"].Width = 200;
            grdmentBillDetailInfo.Columns["MEMO"].SortMode = DataGridViewColumnSortMode.NotSortable;
            grdmentBillDetailInfo.Columns["MEMO"].Resizable = DataGridViewTriState.False;
            grdmentBillDetailInfo.AllowUserToAddRows = false;
            grdmentBillDetailInfo.AllowUserToResizeColumns = true;
            grdmentBillDetailInfo.AllowUserToResizeRows = false;
            grdmentBillDetailInfo.RowHeadersVisible = false;
            grdmentBillDetailInfo.RowTemplate.Resizable = DataGridViewTriState.False;
            grdmentBillDetailInfo.RowTemplate.Height = 20;
            grdmentBillDetailInfo.RowTemplate.ReadOnly = true;
        }

        /// <summary>	
        /// <p><b>方法名称</b>InitStoreRoomManger</p>	
        /// <p><b>概要説明	:</b>Control cmbSTOREROOM_MANAGER の初期化する</p>	
        /// <p><b>作成者	:</b>万岗</p>	
        /// <p><b>作成日	:</b>2008/09/01</p>	
        /// </summary>
        private void InitComboBox()
        {
            Method.CmbDataBound("GOODS_GROUP_ID", cmbGOODS_GROUP_ID);
            cmbGOODS_GROUP_ID.SelectedIndex = 0;
            Method.CmbDataBound("STOREROOM_ID", cmbStoreRoom);
            cmbStoreRoom.SelectedIndex = 0;
        }

        /// <summary>	
        /// <p><b>方法名称</b>InitProcess</p>	
        /// <p><b>概要説明	:</b>窗口初始化</p>	
        /// <p><b>作成者	:</b>万岗</p>	
        /// <p><b>作成日	:</b>2008/09/01</p>	
        /// </summary>
        private void InitProcess()
        {
            SetTabIndex();            
            SetEnable();
            InitialGridView();
            InitialGridViewDetail();
            InitComboBox();
            ClearControl();
            IsInitiral = false;
        }        

        /// <summary>	
        /// <p><b>方法名称</b>ShowGrid</p>	
        /// <p><b>概要説明  :</b>検索結果をGridに表示する</p>	
        /// <p><b>作成者	:</b>万岗</p>	
        /// <p><b>作成日	:</b>2008/09/08</p>	
        /// <p><b>修改历史  :</b></p>	
        /// </summary>	
        /// <param type="class" param="model">库存信息表</param>	
        private void BindGridData()
        {
            if (IsInitiral)
            {
                return;
            }
            entitySearch.ClearValue();
            entitySearch.GOODS_NAME = txtGOODS_ID.Text.Trim();
            if (cmbGOODS_GROUP_ID.SelectedIndex != -1)
            {
                entitySearch.GOODS_GROUP_ID = cmbGOODS_GROUP_ID.SelectedValue.ToString().Trim();
            }
            if (cmbStoreRoom.SelectedIndex != -1)
            {
                entitySearch.StoreRoom_ID = cmbStoreRoom.SelectedValue.ToString().Trim();
            }
            grdmentStorageInfo.Rows.Clear();
            ReturnValue rvSearchResult = bll_M012_STORAGESCAN.SearchProcess(entitySearch);
            if (rvSearchResult.IsSuccess == false)
            {
                Method.MessageShow(rvSearchResult.ErrorID, dataName);
                return;
            }
            if (0 == rvSearchResult.ResultDataSet.Tables[0].Rows.Count)
            {
                grdmentBillDetailInfo.Rows.Clear();
                grpSearchResult.Text = strGroupTitle.Replace("@@@","");
                return;
            }
            
            foreach (DataRow row in rvSearchResult.ResultDataSet.Tables[0].Rows)
            {
                grdmentStorageInfo.Rows.Add((grdmentStorageInfo.Rows.Count + 1).ToString(),
                    row["GOODS_ID"].ToString(),/*商品编号*/
                    row["GOODS_NO"].ToString().Trim(),/*商品条码*/
                    row["GOODS_NM"].ToString(),/*商品名称*/
                    row["GOODS_GROUP_ID"].ToString(), /*商品分类编号*/
                    row["GOODS_GROUP_NM"].ToString(),/*商品分类*/
                    NumPriceFormat(row["UNITS"].ToString().Trim()),/*数量*/
                    /*row["STOREROOM_NM"].ToString()*/"",/*仓库*/
                    row["PROVIDER"].ToString(), /*供应商*/
                    NumPriceFormat(row["MAX_WARN"].ToString().Trim()),/**/
                    NumPriceFormat(row["MIN_WARN"].ToString().Trim()),/**/
                    /*row["STOREROOM_ID"].ToString()*/"");/*仓库编号*/
            }
            grpSearchResult.Text = strGroupTitle.Replace("@@@","   共" + grdmentStorageInfo.Rows.Count.ToString() + "件");
            //if (grdmentStorageInfo.Rows.Count > 21)
            //{
            //    grdmentStorageInfo.Columns["GOODS_NM"].Width = 145;
            //}
            //else
            //{
            //    grdmentStorageInfo.Columns["GOODS_NM"].Width = 164;
            //}
        }

        protected void ShowGridDetail(string strGoodID)
        {
            ReturnValue rvGoods;
            MODEL.MOD_M007_GOODS modelM007 = new XiaoGang.Soft.XGWMS.MODEL.MOD_M007_GOODS();
            modelM007.GOODS_ID = strGoodID;
            rvGoods = bll_M007.GetSingleData(modelM007);
            if (rvGoods.IsSuccess == false)
            {
                Method.MessageShow(rvGoods.ErrorID, dataName);
                return;
            }

            if (rvGoods.ResultDataSet.Tables[0].Rows.Count > 0)
            {
                lbGOODS_ID.Text = strGoodID;
                lbGOODS_NM1.Text = rvGoods.ResultDataSet.Tables[0].Rows[0]["GOODS_NM1"].ToString();
                lbGOODS_GROUP.Text = rvGoods.ResultDataSet.Tables[0].Rows[0]["GOODS_GROUP_NM"].ToString();
                lbPROVIDER.Text = rvGoods.ResultDataSet.Tables[0].Rows[0]["PROVIDER"].ToString();
                lbMEMO.Text = rvGoods.ResultDataSet.Tables[0].Rows[0]["MEMO"].ToString();
            }

            //取得商品[进][出][总]合计
            rvGoods = bll_M014BILLSCAN.GetAllUnits(strGoodID);
            if (rvGoods.IsSuccess == false)
            {
                Method.MessageShow(rvGoods.ErrorID, dataName);
                return;
            }
            if (rvGoods.ResultDataSet.Tables[0].Rows.Count > 0)
            {
                lbAllUnits.Text = "进货:[" + rvGoods.ResultDataSet.Tables[0].Rows[0]["ALLUNITS_IN"].ToString()
                    + "] 销售:[" + rvGoods.ResultDataSet.Tables[0].Rows[0]["ALLUNITS_OUT"].ToString()                    
                    + "] 盘存:[" + rvGoods.ResultDataSet.Tables[0].Rows[0]["ALLUNITS_Stocktaking"].ToString()
                    + "] 库存:[" + rvGoods.ResultDataSet.Tables[0].Rows[0]["ALLUNITS"].ToString()+"]";
            }

            rvGoods = bll_M014BILLSCAN.SearchStorageDetail(strGoodID);

            if (rvGoods.IsSuccess == false)
            {
                Method.MessageShow(rvGoods.ErrorID, dataName);
                return;
            }
            grdmentBillDetailInfo.Rows.Clear();
            foreach (DataRow row in rvGoods.ResultDataSet.Tables[0].Rows)
            {
                grdmentBillDetailInfo.Rows.Add(
                    (grdmentBillDetailInfo.Rows.Count + 1).ToString(),
                    DateFormat(row["BUSINESS_TIME"].ToString().Replace("/", "")),
                    row["IN_OUT_Name"].ToString().Trim(),
                    row["UNITS"].ToString().Trim(),
                    row["PRICE"].ToString().Trim() == "-1.0000" ? "" : string.Format("{0:f2}", decimal.Parse(row["PRICE"].ToString().Trim())),
                    row["MEMO"].ToString().Trim());
            }
        }

        /// <summary>
        /// <p><b>方法名称</b>CheckProcess</p>
        /// <p><b>概要説明  :</b>画面のデータのＣＨＥＣＫ</p>
        /// <p><b>作成者	:</b>万岗</p>
        /// <p><b>作成日	:</b>2008/09/08</p>
        /// <p><b>修改历史  :</b></p>
        /// </summary>
        /// <param type = "string" para="strConstrolName">控件名称</param>
        /// <returns type = "Boolean">　True:成功   False:失敗 </returns>
        protected override bool CheckProcess(string strConstrolName)
        {
            switch (strConstrolName)
            {               
                case "txtGOODS_ID":
                    if (Method.CheckIsNumber(txtGOODS_ID.Text.Trim(), 12, true, true) == false)
                    {
                        Method.MessageShow(GlobalVal.glostrMsg, dataName);
                        txtGOODS_ID.Focus();
                        txtGOODS_ID.SelectAll();
                        return false;
                    }                    
                    break;
            }
            return true;
        }

        /// <summary>
        /// <p><b>方法名：</b>CheckProcessLoop</p>	
        /// <p><b>概要説明:</b>画面のデータのＣＨＥＣＫ</p>	
        /// <p><b>作成者	:</b>万岗</p>	
        /// <p><b>作成日	:</b>2008/09/08</p>	
        /// <p><b>修改历史:</b></p>	
        /// </summary>	
        /// <param type = "enum" para="enumOperation">枚举状态</param>	
        /// <returns type = "Boolean">　True:成功   False:失敗 </returns>
        private bool CheckProcessLoop(enumOperation emOperation)
        {
            switch (emOperation)
            {
                case enumOperation.Search: 
                    if (CheckProcess("txtGOODS_ID") == false) return false;
                    break;             
            }
            return true;
        }

        /// <summary>
        /// <p><b>方法名称</b>DateFormat</p>
        /// <p><b>概要説明  :</b>date data format</p>
        /// <p><b>作成者	:</b>万岗</p>
        /// <p><b>作成日	:</b>2008/09/08</p>
        /// <p><b>修改历史  :</b></p>
        /// </summary>
        /// <param type="string" name="strValue">没有格式化的字符串信息</param> 
        /// <returns type="string">格式化后的字符串信息</returns>
        protected string DateFormat(string strValue)
        {
            if (strValue.Length < 8)
            {
                return strValue;
            }
            return strValue.Substring(0, 4) + "/" +
                strValue.Substring(4, 2) + "/" +
                strValue.Substring(6, 2);

        }

        /// <summary>	
        /// <p><b>方法名称</b>NumPriceFormat</p>	
        /// <p><b>概要説明  :</b>num and price data format</p>	
        /// <p><b>作成者	:</b>万岗</p>	
        /// <p><b>作成日	:</b>2008/09/08</p>	
        /// <p><b>修改历史  :</b></p>	
        /// </summary>
        /// <param type="string" name="strValue">没有格式化的字符串信息</param> 
        /// <returns type="string">格式化后的字符串信息</returns>
        protected string NumPriceFormat(string strValue)
        {
            string strTemp = strValue;
            if (strValue.Length > 6)
            {
                strTemp = strValue.Substring(0, strValue.Length - 6) + ","
                    + strValue.Substring((strValue.Substring(0, strValue.Length - 6)).Length, 3)
                    + "," + strValue.Substring(strValue.Length - 3, 3);

            }
            else if (strValue.Length > 3)
            {
                strTemp = strValue.Substring(0, strValue.Length - 3) + ","
                + strValue.Substring((strValue.Substring(0, strValue.Length - 3)).Length, 3);
            }
            return strTemp;
        }    

        #endregion

        #region 事件

        private void M012_STORAGESCAN_Load(object sender, EventArgs e)
        {
            blFormLoad = true;
            InitProcess();
            txtGOODS_ID.Focus();
        }

        protected override void AllTextBox_KeyDown(object sender, KeyEventArgs e)
        {
            base.AllTextBox_KeyDown(sender, e);
        }

        private void AllTextBox_KeyPrecess(object sender, KeyPressEventArgs e)
        {
            string strValue = ((TextBox)sender).Text.Trim();
            switch (((TextBox)sender).Name)
            {
                case "txtGOODS_ID":
                    FormBase.UKeyPress(e, InputType.Num);
                    break;
            }
        }

        private void AllTextBox_GotFocus(object sender, EventArgs e)
        {
            string strValue = ((TextBox)sender).Text.Trim();
            switch (((TextBox)sender).Name)
            {                
                case "txtGOODS_ID":
                    ((TextBox)sender).SelectAll();
                    ((TextBox)sender).ImeMode = ImeMode.Hiragana;
                    break;             
            }
        }

        private void AllButton_Click(object sender, EventArgs e)
        {
            if (Cursor.Current == Cursors.WaitCursor)
            {
                return;
            }
            Cursor.Current = Cursors.WaitCursor;

            string strButtonName = ((Button)sender).Name;

            switch (strButtonName)
            {
                #region btnGoodsIDSearch
                case "btnGoodsIDSearch":
                    {
                        M007_GOODS mstr_M007_GOODS = new M007_GOODS(true);
                        string strGoodID = "";
                        //string strGoodNM = "";
                        //string strSELLING_PRICE = "";
                        mstr_M007_GOODS.StartPosition = FormStartPosition.CenterScreen;
                        //mstr_M007_GOODS.ShowDialog(ref strGoodID, ref strGoodNM, ref strSELLING_PRICE,"");
                        mstr_M007_GOODS.ShowSearchGoodsDialog(this, "", "", "");
                        txtGOODS_ID.Text = strGoodID.Trim();
                    }
                    break;
                #endregion
                                   
                #region btnPrint
                case "btnPrint":
                    Print();
                    break;

                #region btnExit
                case "btnExit":
                    this.Close();
                    break;
                #endregion
                #endregion
            }

            Cursor.Current = Cursors.Default;
        }

        private void M012_STORAGESCAN_KeyDown(object sender, KeyEventArgs e)
        {
            switch (e.KeyCode)
            {
                case Keys.F5:
                    AllButton_Click(btnPrint, e);
                    break;
                case Keys.Escape:
                    AllButton_Click(btnExit, e);
                    break;
            }
        }

        private void cmbGOODS_GROUP_ID_GotFocus(object sender,EventArgs e)
        {
            cmbGOODS_GROUP_ID.SelectAll();
        }

        private void M012_STORAGESCAN_Activated(object sender, EventArgs e)
        {
            if (!blFormLoad)
            {
                string strValueStoreRoom = cmbStoreRoom.SelectedValue.ToString();
                string strValueGoodsGroup = cmbGOODS_GROUP_ID.SelectedValue.ToString();
                Method.CmbDataBound("STOREROOM_ID", cmbStoreRoom);
                foreach (System.Data.DataRowView drStore in this.cmbStoreRoom.Items)
                {
                    if (strValueStoreRoom == drStore["STOREROOM_ID"].ToString().Trim())
                    {
                        cmbStoreRoom.SelectedValue = strValueStoreRoom;
                        return;
                    }
                }
                cmbStoreRoom.SelectedIndex = 0;
                Method.CmbDataBound("GOODS_GROUP_ID", cmbGOODS_GROUP_ID);
                foreach (System.Data.DataRowView drGoods in this.cmbGOODS_GROUP_ID.Items)
                {
                    if (strValueGoodsGroup == drGoods["GOODS_GROUP_ID"].ToString().Trim())
                    {
                        cmbGOODS_GROUP_ID.SelectedValue = strValueGoodsGroup;
                        return;
                    }
                }
                cmbGOODS_GROUP_ID.SelectedIndex = 0;
            }
            blFormLoad = false;
        }

        #endregion

        private void grdmentStorageInfo_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            if (0 == grdmentStorageInfo.Rows.Count || e.RowIndex == -1)
            {
                return;
            }
            string strGOODS_ID = grdmentStorageInfo.CurrentRow.Cells["GOODS_ID"].Value.ToString();
            M013_STORAGE_Detail frm_M013_STORAGE_Detail = new M013_STORAGE_Detail(strGOODS_ID);
            frm_M013_STORAGE_Detail.StartPosition = FormStartPosition.CenterScreen;
            frm_M013_STORAGE_Detail.ShowDialog();
        }

        private void grdmentStorageInfo_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            string strGOODS_ID = grdmentStorageInfo.CurrentRow.Cells["GOODS_ID"].Value.ToString();
            ShowGridDetail(strGOODS_ID);
            grpBillDetailInfo.Text = "共有" + grdmentBillDetailInfo.Rows.Count + "条商品流水信息";
        }

        private void grdmentStorageInfo_SelectionChanged(object sender, EventArgs e)
        {
            string strGOODS_ID = grdmentStorageInfo.CurrentRow.Cells["GOODS_ID"].Value.ToString();
            ShowGridDetail(strGOODS_ID);
            grpBillDetailInfo.Text = "共有" + grdmentBillDetailInfo.Rows.Count + "条商品流水信息";
        }

        /// <summary>
        /// 打印
        /// </summary>
        private void Print()
        {
            //每次生成Excel前强制进行垃圾回收
            GC.Collect();
            if (Method.MessageShow("Q12014", dataName) == DialogResult.Yes)//确定要进行打印吗，本功能将打开一个Excel文件，请在Excel文件中设置好格式进行打印。
            { 
            //检索数据源
            MODEL.MOD_M012_STORAGESCAN model = new XiaoGang.Soft.XGWMS.MODEL.MOD_M012_STORAGESCAN();
            model.GOODS_NAME = txtGOODS_ID.Text.Trim();
            if (cmbGOODS_GROUP_ID.SelectedIndex != -1)
            {
                model.GOODS_GROUP_ID = cmbGOODS_GROUP_ID.SelectedValue.ToString().Trim();
            }
            else
            {
                model.GOODS_GROUP_ID = "";
            }
            if (cmbStoreRoom.SelectedIndex != -1)
            {
                model.StoreRoom_ID = cmbStoreRoom.SelectedValue.ToString().Trim();
            }
            else
            {
                model.StoreRoom_ID = "";
            }
            ReturnValue rvSearchResult = bll_M012_STORAGESCAN.SearchProcess(model);
            if (rvSearchResult.IsSuccess == false)
            {
                Method.MessageShow(rvSearchResult.ErrorID, dataName);
                return;
            }
            if (0 == rvSearchResult.ResultDataSet.Tables[0].Rows.Count)
            {
                MessageBox.Show("没有数据！");
                return;
            }
            DataTable tb = rvSearchResult.ResultDataSet.Tables[0];
            //创建一个Excel文件  
            object missing = Missing.Value;
            Excel.Application appExcel = new Excel.Application();
            Excel.Workbooks myBooks = appExcel.Workbooks;
            //工作薄是否可见
            appExcel.Visible = false;
            //向Excel中添加一个工作薄
            Excel._Workbook workbook = myBooks.Add(Excel.XlWBATemplate.xlWBATWorksheet);
            //向工作薄中添加一个Sheet
            Excel.Worksheet mySheet = (Excel.Worksheet)workbook.Worksheets.Add(Missing.Value, Missing.Value, 1, Missing.Value);
            //使某个Sheet作为当前选择项
            ((Excel.Worksheet)appExcel.ActiveWorkbook.Sheets[1]).Select(Missing.Value);
            
            //myExcel.Application.Workbooks.Add(true); 
            //第一行为报表名称  
            //myExcel.Cells[1, 1] = "库存报表";
            mySheet.get_Range("A1", Missing.Value).Value2 = "库存报表";
            //这是单元格居中对齐
            mySheet.get_Range("A1", Missing.Value).HorizontalAlignment = Excel.XlVAlign.xlVAlignCenter;
            //这是行高
            mySheet.get_Range("A1", Missing.Value).RowHeight = 30;
            //设置字体
            mySheet.get_Range("A1", Missing.Value).Font.Bold = true;
            mySheet.get_Range("A1", Missing.Value).Font.Size = 15;
            //设置整个报表的标题为跨列居中
            //mySheet.get_Range("A1", Missing.Value).HorizontalAlignment = xlHAlignCenterAcrossSelection;
            //合并单元格
            mySheet.get_Range(appExcel.Cells[1, 1], appExcel.Cells[1, 5]).Merge(false);

            appExcel.Cells[2, 1] = "'商品编号";
            mySheet.get_Range("A2", Missing.Value).ColumnWidth = 12;
            mySheet.get_Range("A2", Missing.Value).Font.Bold = true;
            appExcel.Cells[2, 2] = "'商品条码";
            mySheet.get_Range("B2", Missing.Value).ColumnWidth = 13;
            mySheet.get_Range("B2", Missing.Value).Font.Bold = true;
            appExcel.Cells[2, 3] = "'商品名称";
            mySheet.get_Range("C2", Missing.Value).ColumnWidth = 38;
            mySheet.get_Range("C2", Missing.Value).Font.Bold = true;
            appExcel.Cells[2, 4] = "'商品种类";
            mySheet.get_Range("D2", Missing.Value).ColumnWidth = 9;
            mySheet.get_Range("D2", Missing.Value).Font.Bold = true;
            appExcel.Cells[2, 5] = "'数量";
            mySheet.get_Range("E2", Missing.Value).ColumnWidth = 5;
            mySheet.get_Range("E2", Missing.Value).Font.Bold = true;
            //逐行写入数据，  
            int intRow = 3;
            for (int i = 0; i < tb.Rows.Count; i++)
            {
                //以单引号开头，表示该单元格为纯文本  
                appExcel.Cells[intRow + i, 1] = "'" + tb.Rows[i]["GOODS_ID"].ToString();
                appExcel.Cells[intRow + i, 2] = "'" + tb.Rows[i]["GOODS_NO"].ToString();
                appExcel.Cells[intRow + i, 3] = "'" + tb.Rows[i]["GOODS_NM"].ToString();
                appExcel.Cells[intRow + i, 4] = "'" + tb.Rows[i]["GOODS_GROUP_NM"].ToString();
                appExcel.Cells[intRow + i, 5] = tb.Rows[i]["UNITS"].ToString();
            }
            //让Excel文件可见
            //工作薄是否可见
            appExcel.Visible = true;
        }
        }        

        /// <summary>
        /// SaveFile
        /// </summary>
        /// <param name="strMobanName"></param>
        /// <param name="filename"></param>
        private void SaveFile(string strMobanName, out string filename)
        {
            //System.Windows.Forms.Application.StartupPath.Trim() + "\\" +
            SaveFileDialog mySave = new SaveFileDialog();
            mySave.DefaultExt = "xls";
            mySave.Filter = "Excel文件|*.xls";
            if (mySave.ShowDialog() != DialogResult.OK)
            {
                filename = null;
                return;
            }
            else
            {
                filename = mySave.FileName;
                string filenameold = mySave.FileName;
                FileInfo mode = new FileInfo(strMobanName);
                try
                {
                    mode.CopyTo(filename, true);
                }
                catch (Exception ee)
                {
                    MessageBox.Show(ee.Message);
                    return;
                }
            }
        }

        /// <summary>
        /// 查询条件改变
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void QueryChanged(object sender, EventArgs e)
        {
            if (this.Cursor == Cursors.WaitCursor)
            {
                return;
            }
            BindGridData();
        }
    }
}